package com.karry.util;

import com.karry.pojo.Blog;
import com.karry.pojo.DianZan;
import com.karry.service.DianZanService;
import com.karry.service.impl.DianZanServiceImpl;

import java.util.ArrayList;
import java.util.List;

/**
 *  点赞工具类
 * **/
public class DianZanUtil {

    public static DianZanService ds = new DianZanServiceImpl();

    //查询一个列表点赞情况
    public static ArrayList<Integer> searchBlogListDianCount(List<Blog> blogs){

        ArrayList<Integer> list = new ArrayList<>();

        ArrayList<DianZan> dianZanArrayList = ds.searchAll();


        for (Blog blog : blogs) {
            int id = blog.getId();
            int count = 0;
            for (DianZan dianZan : dianZanArrayList) {
                if (dianZan.getBlogId() == id){
                    count++;
                }
            }
            list.add(count);
        }

        return list;
    }

    //查询某个用户是否点赞了某篇文章
    public static int searchUserDianBlogStatus(int blogID, int userID){

        return ds.searchUserDianBlogStatus(blogID, userID);
    }

    public static int searchBlogDianCount(int id){
        return ds.searchBlogDianCount(id);
    }

    //点赞
    public static int dianZan(int blogID, int userID){

        return ds.dianZan(blogID, userID);
    }

    //取消点赞
    public static int cancelDianZan(int blogID, int userID){

        return ds.cancelDian(blogID, userID);
    }

}
